import { _decorator, Node } from 'cc';
import { ListRender } from '../../Basic/Component/ListRender';
import { autoNode } from '../../Basic/Manager/BaseManager';
import { MainModel_Ins } from './MainModel';

const { ccclass, property } = _decorator;
@ccclass('WoodItem')
export class WoodItem extends ListRender {
  @autoNode()
  tree_1: Node;
  @autoNode()
  tree_2: Node;
  data: number;
  dataChanged(...args: unknown[]): void {
    this.tree_1.active = this.data === 1;
    this.tree_2.active = this.data === 2;
  }

  hit() {
    if (this.data <= 0) return;
    this.data--;
    this.dataChanged();
    MainModel_Ins.basePanel.playAniEff(this.data === 1 ? 'pre_eff_tree_2' : 'pre_eff_tree_1', this.node.getPosition());
    MainModel_Ins.basePanel.playAniEff('pre_eff_wood', this.node.getPosition(), () => MainModel_Ins.basePanel.addCoin());
  }
}
